package org.csu.pm.controller;

import org.csu.pm.annotation.AuthUser;
import org.csu.pm.common.BaseResponse;
import org.csu.pm.entity.Room;
import org.csu.pm.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/rooms")
public class RoomController {

    @Autowired
    private RoomService roomService;

    @GetMapping
    public BaseResponse<List<Room>> listAllRooms() {
        return roomService.getRoomList();
    }

    @GetMapping("/{id}")
    public BaseResponse<Room> getRoomById(@PathVariable("id")Long id) {
        return roomService.getRoomById(id);
    }

    @PostMapping("/{id}")
    public BaseResponse<Room> createRoom(@RequestBody Room room, @PathVariable("id")Long id, @AuthUser String userId) {
//        System.out.println("当前新增的会议室id为:" + id);
//        System.out.println("当前登录的用户id为:" + userId);
        // userId 为 user表的 现在需要userInfo表的
        return roomService.createRoom(room, id, Long.valueOf(userId));
    }

    @DeleteMapping("/{id}")
    public BaseResponse<String> deleteRoomById(@PathVariable("id")Long id, @AuthUser String userId) {
        return roomService.deleteRoomById(id, Long.valueOf(userId));
    }

    @PutMapping("/{id}")
    public BaseResponse<Room> updateRoom(@RequestBody Room room, @PathVariable("id")Long id, @AuthUser String userId) {
        return roomService.updateRoom(room, id, Long.valueOf(userId));
    }

    @PutMapping("/status/{id}")
    public BaseResponse<String> changeRoomStatus(@PathVariable("id")Long id, @AuthUser String userId) {
        return roomService.changeRoomStatus(id, Long.valueOf(userId));
    }


}
